package com.examsystem.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.examsystem.common.PapersResult;
import com.examsystem.common.ResultJson;
import com.examsystem.common.StatusAndMsg;
import com.examsystem.dao.exame_paperMapper;
import com.examsystem.dao.exame_qb_paperMapper;
import com.examsystem.dao.exame_questionsbankMapper;
import com.examsystem.dao.exame_questionsoptionMapper;
import com.examsystem.dao.exame_user_subjectMapper;
import com.examsystem.entity.exame_paper;
import com.examsystem.entity.exame_paperExample;
import com.examsystem.entity.exame_qb_paper;
import com.examsystem.entity.exame_qb_paperExample;
import com.examsystem.entity.exame_user;
import com.examsystem.entity.exame_user_subject;
import com.examsystem.entity.exame_user_subjectExample;
import com.examsystem.entity.exame_user_subjectExample.Criteria;
import com.examsystem.service.OnlineExameService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@Service
public class OnlineExameServiceImpl implements OnlineExameService{
	
	@Autowired
	private exame_paperMapper paperMapper;
	
	
	/**
	 * 考生登录后能查询到本人相关的考试信息。
	 * @return
	 */
	@Override
	public ResultJson selectks(exame_user user,Integer page,Integer pageSize) {
		ResultJson result=null;
		String username=user.getUsername();
		PageHelper.startPage(page,pageSize);
		List<PapersResult> list = paperMapper.selectByUsername(username);
		if(list.size()==0||null==list) {
			result=new ResultJson(StatusAndMsg.NODATA.getStatus(), StatusAndMsg.NODATA.getMsg(), null);
		}else {
			PageInfo<PapersResult> pageInfo=new PageInfo<>(list, pageSize);
			result=new ResultJson(StatusAndMsg.YES.getStatus(), StatusAndMsg.YES.getMsg(), pageInfo);
		}
		return result;
	}

	/**
	 * 考试选择考试后可以进行在线考试。
	 * @return
	 */
	@Override
	public ResultJson onlineks() {
		// TODO Auto-generated method stub
		return null;
		/**
		 * 
				//取试卷id
				ArrayList<Integer> pIDs=new ArrayList<>();
				for(exame_paper ep:list2) {
					pIDs.add(ep.getPid());
				}
				//根据试卷id查询这试卷的所有试题id
				exame_qb_paperExample example1=new exame_qb_paperExample();
				com.examsystem.entity.exame_qb_paperExample.Criteria criteria3 = example1.createCriteria();
				criteria3.andPidIn(pIDs);
				List<exame_qb_paper> list3 = qbPaperMapper.selectByExample(example1);
				//判断有无
				if(list2.size()==0||null==list2) {
					result=new ResultJson(StatusAndMsg.NODATA.getStatus(), StatusAndMsg.NODATA.getMsg(), "无记录");
				}else {
					//取试题id
					ArrayList<Integer> qbIDs=new ArrayList<>();
					for(exame_qb_paper qb:list3) {
						qbIDs.add(qb.getQbid());
					}
					//根据题目查这题的选项
					
				}
		 */
	}

}
